package com.wxy.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wxy.entity.Staff;
import com.wxy.mapper.StaffMapper;
import com.wxy.vo.UserWages;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wxy
 * @since 2022-01-12
 */
@RestController
@RequestMapping("/staff")
public class StaffController {

    @Autowired
    StaffMapper staffMapper;

    //echart图
    @GetMapping("/echartUserWages")
    public UserWages echartUserWages(
            HttpServletRequest request
    ) {
        String userId = request.getHeader("userId").toString();
        //查出数据
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("userId",userId);
        List<Staff> staffList =  staffMapper.selectList(queryWrapper);
        UserWages userWages = new UserWages();
        List<String> userName = new ArrayList<>();
        List<Integer> wages = new ArrayList<>();
        for (Staff staff : staffList) {
            userName.add(staff.getName().toString());
        }
        for (Staff staff : staffList) {
            wages.add(Integer.valueOf(staff.getWages().toString()));
        }
        userWages.setName(userName);
        userWages.setWages(wages);
        return userWages;
    }
}

